//////////////////////////////////////////////////////////////////////////
public:
	/// <summary>
	/// Decrements CvMat data reference counter and deallocates the data if
	/// it reaches 0
	/// </summary>
	static void DecRefData(ManagedArr^ arr)
	{
		cvDecRefData(arr->ToCvArrPointer());
	}

	/// <summary>
	/// Increments CvMat data reference counter
	/// </summary>
	/// <returns></returns>
	static int IncRefData(ManagedArr^ arr)
	{
		return  cvIncRefData(arr->ToCvArrPointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="arr"></param>
	/// <param name="submat"></param>
	/// <returns></returns>
	static ManagedMat^ GetRow(ManagedArr^ arr, ManagedMat^ submat, int row)
	{
		return gcnew ManagedMat(cvGetRow(arr->ToCvArrPointer(), submat->ToCvMatPointer(), row), false);
	}

	/// <summary>
	/// </summary>
	/// <param name="arr"></param>
	/// <param name="submat"></param>
	/// <returns></returns>
	static ManagedMat^ GetCol(ManagedArr^ arr, ManagedMat^ submat, int col)
	{
		return gcnew ManagedMat( cvGetCol(arr->ToCvArrPointer(), submat->ToCvMatPointer(), col), false);
	}

	/// <summary>
	/// Releases CvMatND
	/// </summary>
	static void ReleaseMatND(ManagedMatND^% mat)
	{
		CvMatND* pmat = mat->ToCvMatNDPointer();
		cvReleaseMatND(&pmat);
		mat->m_pHandle = pmat;
	}

	/// <summary>
	/// returns next sparse array node (or NULL if there is no more nodes)
	/// </summary>
	/// <returns></returns>
	static ManagedSparseNode^ GetNextSparseNode(ManagedSparseMatIterator^ mat_iterator)
	{
		return gcnew ManagedSparseNode(cvGetNextSparseNode((CvSparseMatIterator*)mat_iterator->ToCvSparseMatIteratorPointer()));
	}

	/// <summary>
	/// dst(mask) = src(mask) - value = src(mask) + (-value)
	/// </summary>
	/// <param name="src"></param>
	/// <param name="value"></param>
	/// <param name="dst"></param>
	static void SubS(ManagedArr^ src, NAMESPACE::Scalar value, ManagedArr^ dst, ManagedArr^ mask)
	{
		cvSubS(src->ToCvArrPointer(), *(CvScalar*)&value, dst->ToCvArrPointer(), mask->ToCvArrPointer());
	}

	/// <summary>
	/// dst(mask) = src(mask) - value = src(mask) + (-value)
	/// </summary>
	/// <param name="src"></param>
	/// <param name="value"></param>
	static void SubS(ManagedArr^ src, NAMESPACE::Scalar value, ManagedArr^ dst)
	{
		cvSubS(src->ToCvArrPointer(), *(CvScalar*)&value, dst->ToCvArrPointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="seq"></param>
	/// <returns></returns>
	static ManagedSeq^ CloneSeq(ManagedSeq^ seq, ManagedMemStorage^ storage)
	{
		return gcnew ManagedSeq(cvCloneSeq(seq->ToCvSeqPointer(), storage->ToCvMemStoragePointer()));
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static ManagedSeq^ CloneSeq(ManagedSeq^ seq)
	{
		return gcnew ManagedSeq(cvCloneSeq(seq->ToCvSeqPointer()));
	}

	/// <summary>
	/// Fast variant of cvSetAdd
	/// </summary>
	/// <returns></returns>
	static ManagedSetElem^ SetNew(ManagedSet^ set_header)
	{
		return gcnew ManagedSetElem(cvSetNew(set_header->ToCvSetPointer()));
	}

	/// <summary>
	/// Removes set element given its pointer
	/// </summary>
	/// <param name="set_header"></param>
	static void SetRemoveByPtr(ManagedSet^ set_header, ManagedSetElem^ elem)
	{
		cvSetRemoveByPtr(set_header->ToCvSetPointer(), elem->ToCvSetElemPointer());
	}

	/// <summary>
	/// Returns a set element by index. If the element doesn't belong to the set,
	/// NULL is returned
	/// </summary>
	/// <param name="set_header"></param>
	/// <returns></returns>
	static ManagedSetElem^ GetSetElem(ManagedSet^ set_header, int index)
	{
		return gcnew ManagedSetElem(cvGetSetElem(set_header->ToCvSetPointer(), index));
	}

	/// <summary>
	/// </summary>
	/// <param name="img"></param>
	/// <param name="box"></param>
	/// <param name="color"></param>
	/// <param name="thickness"></param>
	/// <param name="line_type"></param>
	static void EllipseBox(ManagedArr^ img, NAMESPACE::Box2D box, NAMESPACE::Scalar color, int thickness, LineTypeFlag line_type, int shift)
	{
		cvEllipseBox(img->ToCvArrPointer(), *(CvBox2D*)&box, *(CvScalar*)&color, thickness, (int)line_type, shift);
	}

	/// <summary>
	/// </summary>
	/// <param name="img"></param>
	/// <param name="box"></param>
	/// <param name="color"></param>
	/// <param name="thickness"></param>
	static void EllipseBox(ManagedArr^ img, NAMESPACE::Box2D box, NAMESPACE::Scalar color, int thickness, LineTypeFlag line_type)
	{
		cvEllipseBox(img->ToCvArrPointer(), *(CvBox2D*)&box, *(CvScalar*)&color, thickness, (int)line_type);
	}

	/// <summary>
	/// </summary>
	/// <param name="img"></param>
	/// <param name="box"></param>
	/// <param name="color"></param>
	static void EllipseBox(ManagedArr^ img, NAMESPACE::Box2D box, NAMESPACE::Scalar color, int thickness)
	{
		cvEllipseBox(img->ToCvArrPointer(), *(CvBox2D*)&box, *(CvScalar*)&color, thickness);
	}

	/// <summary>
	/// </summary>
	/// <param name="img"></param>
	/// <param name="box"></param>
	static void EllipseBox(ManagedArr^ img, NAMESPACE::Box2D box, NAMESPACE::Scalar color)
	{
		cvEllipseBox(img->ToCvArrPointer(), *(CvBox2D*)&box, *(CvScalar*)&color);
	}

	/// <summary>
	/// </summary>
	/// <param name="scale"></param>
	/// <returns></returns>
	static NAMESPACE::Font Font(double scale, int thickness)
	{
		return *(NAMESPACE::Font*)&cvFont(scale, thickness);
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static NAMESPACE::Font Font(double scale)
	{
		return *(NAMESPACE::Font*)&cvFont(scale);
	}

	/// <summary>
	/// </summary>
	/// <param name="node"></param>
	/// <returns></returns>
	static int ReadInt(ManagedFileNode^ node, int default_value)
	{
		return cvReadInt(node->ToCvFileNodePointer(), default_value);
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static int ReadInt(ManagedFileNode^ node)
	{
		return cvReadInt(node->ToCvFileNodePointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <param name="name"></param>
	/// <returns></returns>
	static int ReadIntByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name, int default_value)
	{
		return cvReadIntByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name), default_value);
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <returns></returns>
	static int ReadIntByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name)
	{
		return cvReadIntByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name));
	}

	/// <summary>
	/// </summary>
	/// <param name="node"></param>
	/// <returns></returns>
	static double ReadReal(ManagedFileNode^ node, double default_value)
	{
		return cvReadReal(node->ToCvFileNodePointer(), default_value);
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static double ReadReal(ManagedFileNode^ node)
	{
		return cvReadReal(node->ToCvFileNodePointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <param name="name"></param>
	/// <returns></returns>
	static double ReadRealByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name, double default_value)
	{
		return cvReadRealByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name), default_value);
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <returns></returns>
	static double ReadRealByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name)
	{
		return cvReadRealByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name));
	}

	/// <summary>
	/// </summary>
	/// <param name="node"></param>
	/// <returns></returns>
	static System::String^ ReadString(ManagedFileNode^ node, System::String^ default_value)
	{
		return Marshal::PtrToStringAnsi(IntPtr((char*)cvReadString(node->ToCvFileNodePointer(), auto_string(default_value))));
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static System::String^ ReadString(ManagedFileNode^ node)
	{
		return Marshal::PtrToStringAnsi(IntPtr((char*)cvReadString(node->ToCvFileNodePointer())));
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <param name="name"></param>
	/// <returns></returns>
	static System::String^ ReadStringByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name, System::String^ default_value)
	{
		return Marshal::PtrToStringAnsi(IntPtr((void*)cvReadStringByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name), auto_string(default_value))));
	}

	/// <summary>
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <returns></returns>
	static System::String^ ReadStringByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name)
	{
		return Marshal::PtrToStringAnsi(IntPtr((void*)cvReadStringByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name))));
	}

	/// <summary>
	/// decodes standard or user-defined object and returns it
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <param name="name"></param>
	/// <returns></returns>
	static IntPtr ReadByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name, ManagedAttrList^ attributes)
	{
		return IntPtr(cvReadByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name), attributes->ToCvAttrListPointer()));
	}

	/// <summary>
	/// decodes standard or user-defined object and returns it
	/// </summary>
	/// <param name="fs"></param>
	/// <param name="map"></param>
	/// <returns></returns>
	static IntPtr ReadByName(ManagedFileStorage^ fs, ManagedFileNode^ map, System::String^ name)
	{
		return IntPtr(cvReadByName(fs->ToCvFileStoragePointer(), map->ToCvFileNodePointer(), auto_string(name)));
	}


	//////////////////////////////////////////////////////////////////////////